package com.ruoyi.web.controller.community.owner;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.OwnerGroup;
import com.ruoyi.community.service.IOwnerGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 群组列表Controller
 * 
 * @author ruoyi
 * @date 2021-08-05
 */
@RestController
@RequestMapping("/community/owner/group")
public class OwnerGroupController extends BaseController
{
    @Autowired
    private IOwnerGroupService ownerGroupService;

    /**
     * 查询群组列表列表
     */
    @PreAuthorize("@ss.hasPermi('community:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnerGroup ownerGroup)
    {
        startPage();
        List<OwnerGroup> list = ownerGroupService.selectOwnerGroupList(ownerGroup);
        return getDataTable(list);
    }

    /**
     * 导出群组列表列表
     */
    @PreAuthorize("@ss.hasPermi('community:group:export')")
    @Log(title = "群组列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnerGroup ownerGroup)
    {
        List<OwnerGroup> list = ownerGroupService.selectOwnerGroupList(ownerGroup);
        ExcelUtil<OwnerGroup> util = new ExcelUtil<OwnerGroup>(OwnerGroup.class);
        return util.exportExcel(list, "群组列表数据");
    }

    /**
     * 获取群组列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:group:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") String groupId)
    {
        return AjaxResult.success(ownerGroupService.selectOwnerGroupById(groupId));
    }

    /**
     * 新增群组列表
     */
    @PreAuthorize("@ss.hasPermi('community:group:add')")
    @Log(title = "群组列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnerGroup ownerGroup)
    {
        return toAjax(ownerGroupService.insertOwnerGroup(ownerGroup));
    }

    /**
     * 修改群组列表
     */
    @PreAuthorize("@ss.hasPermi('community:group:edit')")
    @Log(title = "群组列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnerGroup ownerGroup)
    {
        return toAjax(ownerGroupService.updateOwnerGroup(ownerGroup));
    }

    /**
     * 删除群组列表
     */
    @PreAuthorize("@ss.hasPermi('community:group:remove')")
    @Log(title = "群组列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable String[] groupIds)
    {
        return toAjax(ownerGroupService.deleteOwnerGroupByIds(groupIds));
    }
}
